//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
#include "eic.h"
#include "CImpressionBouton.h"
#pragma package(smart_init)

#define MODULE_TAG MTAG_CIMPRESSIONBTN
//---------------------------------------------------------------------------

// ValidCtrCheck est utilisé est utilisé pour être sûr que les composants créés n'ont
// aucune fonction virtuelle pure.
//

static inline void ValidCtrCheck(CImpressionBouton *)
{
  new CImpressionBouton(NULL);
}
//---------------------------------------------------------------------------
__fastcall CImpressionBouton::CImpressionBouton(TComponent* Owner)
  : TCustomControl(Owner)
{
  _onChoixOrientationEffectue = NULL;
  _impression = true;
  itemPortrait = NULL;
  itemPaysage = NULL;
  menuPopup = NULL;
  btnImage = NULL;
  btnFleche = NULL;
  Height            = 25;
  Width             = 40;

  btnImage           = new CSpeedButton( this);
  btnImage->Align    = alClient;
  btnImage->Parent   = this;
  btnImage->OnClick = PortraitExecute;

  btnFleche = new TSpeedButton(this);
  btnFleche->Align      = alRight;
  btnFleche->Height = 25;
  btnFleche->Width = 15;
  btnFleche->Parent = this;
  btnFleche->OnClick = btnFlecheClick;
  btnFleche->NumGlyphs  = 2;
  btnFleche->Glyph->LoadFromResourceName(( int)HInstance, "ARROW");

  menuPopup = new TPopupMenu(this);
  itemPortrait = new TMenuItem(NULL);
  itemPortrait->Caption = "Portrait";
  itemPortrait->OnClick = PortraitExecute;
  itemPaysage = new TMenuItem(NULL);
  itemPaysage->Caption = "Paysage";
  itemPaysage->OnClick = PaysageExecute;
  menuPopup->AutoPopup = false;
  menuPopup->Items->Add(itemPortrait);
  menuPopup->Items->Add(itemPaysage);
  SetTypeImpression();
}
//---------------------------------------------------------------------------
__fastcall CImpressionBouton::~CImpressionBouton()
{
  delete btnImage;
  btnImage = NULL;
  delete btnFleche;
  btnFleche = NULL;
  delete itemPortrait;
  itemPortrait = NULL;
  delete itemPaysage;
  itemPaysage = NULL;
  delete menuPopup;
  menuPopup = NULL;
}
//---------------------------------------------------------------------------
void __fastcall CImpressionBouton::btnFlecheClick(TObject *Sender)
{
  TPoint ptScreen( ClientToScreen( TPoint( 0, Height)));
  if( menuPopup)
    menuPopup->Popup( ptScreen.x, ptScreen.y);
}
//---------------------------------------------------------------------------
void __fastcall CImpressionBouton::PortraitExecute(TObject *Sender)
{
  if (_onChoixOrientationEffectue)
    _onChoixOrientationEffectue(this,poPortrait);
}
//---------------------------------------------------------------------------
void __fastcall CImpressionBouton::PaysageExecute(TObject *Sender)
{
  if (_onChoixOrientationEffectue)
    _onChoixOrientationEffectue(this,poLandscape);
}
//---------------------------------------------------------------------------
void __fastcall CImpressionBouton::SetImpression(bool pValeur)
{
  _impression = pValeur;
  SetTypeImpression();
}
//---------------------------------------------------------------------------
void __fastcall CImpressionBouton::SetTypeImpression()
{
  btnImage->Kind = _impression ? bkPrint : bkPreview;
}
//---------------------------------------------------------------------------

namespace Cimpressionbouton
{
  void __fastcall PACKAGE Register()
  {
     TComponentClass classes[1] = {__classid(CImpressionBouton)};
     RegisterComponents("EIC Ctrlstd", classes, 0);
  }
}



